<!-- 
 Copyright 2009 University of  Washington
This code is released under the GPL version 3 - with a copy of the license included
@author Maya Hao Li
 -->
<%@page import="seedpod.webapp.view.Page"%>
<%@page import="seedpod.webapp.LimsSession"%>
<%@page
	import="seedpod.model.custom.SeedpodUser"%>
<%@page
	import="seedpod.webapp.view.servlet.ModelMapViewer"%>

<script type="text/javascript"> 
				function updateClsSelection() {
					new Ajax.Request('../lims/modelMap',
					{
						method:'get',
						parameters: {
							isConcrete: $('concreteCheck').checked, 
							isAbstract: $('abstractCheck').checked,
							isRelation: $('relationCheck').checked
						},
						onSuccess: function(transport) {
							var clsSelection = $('clsSelection');
							var response = transport.responseText;
							clsSelection.update(response);
						},
						onFailure: function() {
							var clsSelection = $('clsSelection');
							clsSelection.update('Sorry, I couldn\'t retrieve cls list.');
						}
					}); 
				}
				
				function loadCreateInstanceForm() {
					new Ajax.Request('../lims/formNewInstance.jsp',
					{
						method:'get',
						parameters: {clsName: $F('clsName') },
						onSuccess: function(transport) {
				   		 	var newInstanceForm = $('newInstanceForm');
				   		 	var response = transport.responseText;
				   		 	newInstanceForm.update(response);
						},
						
						onFailure: function() {
							newInstanceForm.update('Sorry, no cls definition found or service is not available.');
						}
					}); 
				}
				
			</script>

<%
	Page spPage = new Page();
	spPage.addJsLibrary("/javascript/lib/scriptaculous/src/effects.js");
	spPage
			.addJsLibrary("/javascript/lib/scriptaculous/src/scriptaculous.js");
	spPage.addJsLibrary("/javascript/instance.js");
	spPage.addJsLibrary("/javascript/lib/jscommon.js");
	spPage.addJsLibrary("/javascript/calendar.js");

	LimsSession spSession = LimsSession.getSession(request);
	SeedpodUser user = spSession.getUser();

	out.println(spPage.getPageOpenHtml());
	out.println(spPage.getBanner(user));

	String clsName = (String) request
			.getParameter(ModelMapViewer.CLSNAME);
	if (clsName == null || clsName.length() == 0)
		clsName = (String) request.getAttribute(ModelMapViewer.CLSNAME);

	if (clsName == null || clsName.length() == 0)
		clsName = "";

	/* CONTAINER */
	out.println("<div id=\"container\">");

	/* RIGHT RAIL */
	out.println("<div id=\"rightRail\">");

	// TOOLS 
	out.println("<div id=\"toolBox\" class=\"widgetBox\">");
	out.println("<div class=\"widgetBoxTitle\" >Tools</div>");
	out.println("<div class=\"widgetBoxContent\" id=\"tools\">");
	out.println("<script>loadTools('" + clsName + "', 0);</script>");
	out.println("</div>"); // end tools div
	out.println("</div>"); // end toolBox div

	// cls definition
	out.println("<div id=\"definitionBox\" class=\"widgetBox\">");
	out
			.println("<div class=\"widgetBoxTitle\">Class Information</div>");
	out.println("<div class=\"widgetBoxContent\" id=\"clsViewer\">");
	out.println("<script>loadClsViewXML('" + clsName + "');</script>");

	out.println("</div>"); // end clsViewer
	out.println("</div>"); // end definitionBox

	out.println("</div>"); // end right rail

	/* CONTENT*/
	out.println("<div id=\"content\">");

	//CLS SELECTION
	if (clsName.length() == 0) {
%>
<div id="clsSelectionBox">
<form id="clsViewRequestForm2" method="get" action="#"
	onSubmit="return false;">
<table id="clsSelectionTable" cellspacing=2 cellpadding=5>
	<tr>
		<td colspan="4">Select class type to see the options in the drop
		down.</td>
	</tr>
	<tr align="center">
		<td bgcolor="#96CA2D">Concrete<br>
		<input type="checkbox" id="concreteCheck" name="concreteCls" checked
			value="concreteCls" onChange="updateClsSelection()"></td>
		<td bgcolor="#BDE688">Abstract <br>
		<input type="checkbox" id="abstractCheck" name="abstractCls"
			value="abstractCls" onChange="updateClsSelection()"></td>
		<td bgcolor="#4094c6">Relation<br>
		<input type="checkbox" id="relationCheck" name="relationCls"
			value="relationCls" onChange="updateClsSelection()"></td>


		<td bgcolor="#eeeeee">
		<div id="clsSelection"><script type="text/Javascript">this.onLoad=updateClsSelection();				</script>
		</div>

		</td>
	</tr>
	<tr>
		<td colspan=7><input type="submit" id="btn_createInstance"	class="button" value="Create New Instance"
			onClick="loadClsViewXML(); loadTools();  loadCreateInstanceForm(); Effect.toggle('clsSelectionBox', 'slide'); return false"></td>
	</tr>

</table>
</form>
</div>
<!-- clsSelectionBox -->
<%
	} else {
		out.println("<input type=\"hidden\" name=\"clsName\" id=\"clsName\" value=\""			+ clsName + "\">");
		
%>

<div id="newIntanceForm1"><jsp:include page="formNewInstance.jsp?clsName=<%=clsName %>" flush="true"></jsp:include>
</div>
<%
	}
	out.println( "<div id=\"newInstanceForm\"></div>");
	
	out.println("</div>"); // end content
	out.println("</div>"); // end container

	out.println(spPage.getFooter());
	out.println(spPage.getPageEndHtml());
%>


